﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XDL.Framework
{
    /// <summary>
    /// A simple 2d integer vector.
    /// </summary>
    [Serializable]
    public struct Vector2i
    {
        /// <summary>
        /// X
        /// </summary>
        public int X;
        /// <summary>
        /// Y
        /// </summary>
        public int Y;

        /// <summary>
        /// {0,0} vector.
        /// </summary>
        public static Vector2i Zero = new Vector2i(0, 0);

        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public Vector2i(int x, int y)
        {
            X = x;
            Y = y;
        }

        /// <summary>
        /// Add operator.
        /// </summary>
        /// <param name="lo">Left operand.</param>
        /// <param name="ro">Right operand.</param>
        /// <returns></returns>
        public static Vector2i operator +(Vector2i lo, Vector2i ro)
        {
            return new Vector2i(lo.X + ro.X, lo.Y + ro.Y);
        }

        /// <summary>
        /// Scalar operator.
        /// </summary>
        /// <param name="lo">Left operand.</param>
        /// <param name="ro">Right operand.</param>
        /// <returns></returns>
        public static Vector2i operator *(int lo, Vector2i ro)
        {
            return new Vector2i(lo * ro.X, lo * ro.Y);
        }

        /// <summary>
        /// Vector mulitply operator.
        /// </summary>
        /// <param name="lo">Left operand.</param>
        /// <param name="ro">Right operand.</param>
        /// <returns></returns>
        public static Vector2i operator *(Vector2i lo, Vector2i ro)
        {
            return new Vector2i(lo.X * ro.X, lo.Y * ro.Y);
        }

        /// <summary>
        /// Equality operator.
        /// </summary>
        /// <param name="lo">Left operand.</param>
        /// <param name="ro">Right operand.</param>
        /// <returns></returns>
        public static bool operator ==(Vector2i lo, Vector2i ro)
        {
            return lo.X == ro.X && lo.Y == ro.Y;
        }

        public static bool operator !=(Vector2i lo, Vector2i ro)
        {
            return lo.X != ro.X || lo.Y != ro.Y;
        }

        public override bool Equals(object obj)
        {
            if (obj == null)
                return false;
            Vector2i ro = (Vector2i)obj;
            return X == ro.X && Y == ro.Y;
        }

        public override int GetHashCode()
        {
            return X.GetHashCode() + Y.GetHashCode();
        }
    }
}
